import {
  Module,
  MiddlewareConsumer,
  CacheInterceptor,
  CacheModule,
} from '@nestjs/common'
import { CommonModule } from './common/index.module'
import { AuthModule } from './modules/auth/auth.module'
import { AllExceptionsFilter } from './common/filters/AllExceptionsFilter.filter'
import { LoggerMiddleware } from './common/middleware/logger.middleware'
import { HelmetMiddleware } from '@nest-middlewares/helmet'
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'
import { JwtAuthGuard } from './common/guards/jwt-auth.guard'
import { AllInterceptor } from './common/interceptors/all.interceptor'
import { ArticleModule } from './modules/article/article.module'
import { ProvincesController } from './modules/provinces/provinces.controller'
import { FileModule } from './modules/file/file.module'
import { ProductModule } from './modules/product/product.module'
import { AddressModule } from './modules/address/address.module'

const providers = [
  {
    provide: APP_FILTER,
    useClass: AllExceptionsFilter,
  },
  {
    provide: APP_GUARD,
    useClass: JwtAuthGuard,
  },
  {
    provide: APP_INTERCEPTOR,
    useClass: AllInterceptor,
  },
  // {
  //   provide: APP_INTERCEPTOR,
  //   useClass: CacheInterceptor,
  // },
]

@Module({
  imports: [
    CommonModule,
    AuthModule,
    ArticleModule,
    FileModule,
    // CacheModule.register(),
    ProductModule,
    AddressModule,
  ],
  controllers: [ProvincesController],
  providers,
})
export class AppModule {
  configure(consumer: MiddlewareConsumer): any {
    consumer.apply(LoggerMiddleware, HelmetMiddleware).forRoutes('*')
  }
}
